package com.yxhl.km.module.login.mvp;

import com.yxhl.km.MyApplication;
import com.yxhl.km.http.retrofit.IEssenceService;
import com.yxhl.km.module.login.mvp.ResultBean;
import com.yxhl.km.module.login.entity.UserInfoBean;
import com.yxhl.km.module.utils.NetworkUtil;
import com.yxhl.km.module.utils.ToastUtil;
import com.yxhl.km.module.view.DiagUtil;
import com.yxhl.km.mvp.BaseModel;

import java.net.ConnectException;
import java.net.SocketTimeoutException;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by 张亚楠 on 2018/5/21.
 */

public class LoginMoudle extends BaseModel {
    /**
     * 登录返回数据
     *
     * @param phone
     * @param password
     * @param onResultobj
     */

    public void getLoginData(String phone, String password, final ResultBean<UserInfoBean> onResultobj) {

        buildServiceLogin(IEssenceService.class)
                .getPostList(phone, password)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<UserInfoBean>() {
                    @Override
                    public void call(UserInfoBean homeBean) {

                        onResultobj.onResult(homeBean);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwableHandler(throwable);
                    }
                });
    }

    public void throwableHandler(Throwable e) {
        ToastUtil.makeToast(e.getMessage());
    }


}
